# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

inherit webapp eutils

DESCRIPTION="Drupal is a PHP-based open-source platform and content management system for building dynamic web sites offering a broad range of features and services; including user administration, publishing workflow, discussion capabilities, news aggregation, metadata functionalities using controlled vocabularies and XML publishing for content sharing purposes. Equipped with a powerful blend of features and configurability, Drupal can support a diverse range of web projects ranging from personal weblogs to large community-driven sites."
FEATURES="digest" 
HOMEPAGE="http://drupal.org"

IUSE="$IUSE minimal cleanup"
MOD_PV="4.6.0" 
DRUPAL_SITE="http://drupal.org/files/projects/"
DRUPAL_MODS="${DRUPAL_SITE}album-${MOD_PV}.tar.gz
		${DRUPAL_SITE}amazontools-${MOD_PV}.tar.gz
		${DRUPAL_SITE}amazonsearch-${MOD_PV}.tar.gz
		${DRUPAL_SITE}article-${MOD_PV}.tar.gz
		${DRUPAL_SITE}attachment-${MOD_PV}.tar.gz
		${DRUPAL_SITE}bookreview-${MOD_PV}.tar.gz
		${DRUPAL_SITE}bookmarks-${MOD_PV}.tar.g
		${DRUPAL_SITE}buddylist-${MOD_PV}.tar.gz
		${DRUPAL_SITE}chatbox-${MOD_PV}.tar.gz
		${DRUPAL_SITE}codefilter-${MOD_PV}.tar.gz
		${DRUPAL_SITE}commentcloser-${MOD_PV}.tar.gz
		${DRUPAL_SITE}contact_dir-${MOD_PV}.tar.gz
		${DRUPAL_SITE}contextlinks-${MOD_PV}.tar.gz
		${DRUPAL_SITE}customerror-${MOD_PV}.tar.gz
		${DRUPAL_SITE}daily-${MOD_PV}.tar.gz
		${DRUPAL_SITE}dba-${MOD_PV}.tar.gz
		${DRUPAL_SITE}diff-${MOD_PV}.tar.gz
		${DRUPAL_SITE}download_counter-${MOD_PV}.tar.gz
		${DRUPAL_SITE}ecommerce-${MOD_PV}.tar.gz
		${DRUPAL_SITE}event-${MOD_PV}.tar.gz
		${DRUPAL_SITE}excerpt-${MOD_PV}.tar.g
		${DRUPAL_SITE}ezmlm-${MOD_PV}.tar.g
		${DRUPAL_SITE}fckeditor-${MOD_PV}.tar.gz
		${DRUPAL_SITE}feedback-${MOD_PV}.tar.gz
		${DRUPAL_SITE}filemanager-${MOD_PV}.tar.gz
		${DRUPAL_SITE}flexinode-${MOD_PV}.tar.gz
		${DRUPAL_SITE}foaf-${MOD_PV}.tar.gz
		${DRUPAL_SITE}folksonomy-${MOD_PV}.tar.gz
		${DRUPAL_SITE}fontsize-${MOD_PV}.tar.gz
		${DRUPAL_SITE}forms-${MOD_PV}.tar.gz
		${DRUPAL_SITE}form_mail-${MOD_PV}.tar.gz
		${DRUPAL_SITE}freelinking-${MOD_PV}.tar.gz
		${DRUPAL_SITE}front-${MOD_PV}.tar.gz
		${DRUPAL_SITE}gallery-${MOD_PV}.tar.gz
		${DRUPAL_SITE}glossary-${MOD_PV}.tar.gz
		${DRUPAL_SITE}hof-${MOD_PV}.tar.gz
		${DRUPAL_SITE}helpedit-${MOD_PV}.tar.gz
		${DRUPAL_SITE}htmlcorrector-${MOD_PV}.tar.gz
		${DRUPAL_SITE}htmlarea-${MOD_PV}.tar.gz
		${DRUPAL_SITE}image-${MOD_PV}.tar.gz
		${DRUPAL_SITE}img_assist-${MOD_PV}.tar.gz
		${DRUPAL_SITE}i18n-${MOD_PV}.tar.gz
		${DRUPAL_SITE}interwiki-${MOD_PV}.tar.gz
		${DRUPAL_SITE}livediscussions-${MOD_PV}.tar.gz
		${DRUPAL_SITE}mailalias-${MOD_PV}.tar.gz
		${DRUPAL_SITE}mailhandler-${MOD_PV}.tar.gz
		${DRUPAL_SITE}massmailer-${MOD_PV}.tar.gz
		${DRUPAL_SITE}members-${MOD_PV}.tar.gz
		${DRUPAL_SITE}menu_otf-${MOD_PV}.tar.gz
		${DRUPAL_SITE}nodewords-${MOD_PV}.tar.gz
		${DRUPAL_SITE}nodelist-${MOD_PV}.tar.gz
		${DRUPAL_SITE}nmoderation-${MOD_PV}.tar.gz
		${DRUPAL_SITE}node_privacy_byrole-${MOD_PV}.tar.gz
		${DRUPAL_SITE}node_import-${MOD_PV}.tar.gz
		${DRUPAL_SITE}notify-${MOD_PV}.tar.gz
		${DRUPAL_SITE}og-${MOD_PV}.tar.gz
		${DRUPAL_SITE}pathauto-${MOD_PV}.tar.gz
		${DRUPAL_SITE}paypal_framework-${MOD_PV}.tar.gz
		${DRUPAL_SITE}paypal_subscription-${MOD_PV}.tar.gz
		${DRUPAL_SITE}poormanscron-${MOD_PV}.tar.gz
		${DRUPAL_SITE}privatemsg-${MOD_PV}.tar.gz
		${DRUPAL_SITE}quote-${MOD_PV}.tar.gz
		${DRUPAL_SITE}quotes-${MOD_PV}.tar.gz
		${DRUPAL_SITE}recipe-${MOD_PV}.tar.gz
		${DRUPAL_SITE}rsvp-${MOD_PV}.tar.gz
		${DRUPAL_SITE}scheduler-${MOD_PV}.tar.g
		${DRUPAL_SITE}securesite-${MOD_PV}.tar.g
		${DRUPAL_SITE}series-${MOD_PV}.tar.gz
		${DRUPAL_SITE}sidecontent-${MOD_PV}.tar.g
		${DRUPAL_SITE}simpletest-${MOD_PV}.tar.gz
		${DRUPAL_SITE}site_map-${MOD_PV}.tar.g
		${DRUPAL_SITE}sitemenu-${MOD_PV}.tar.gz
		${DRUPAL_SITE}smartypants-${MOD_PV}.tar.gz
		${DRUPAL_SITE}smileys-${MOD_PV}.tar.g
		${DRUPAL_SITE}spam-${MOD_PV}.tar.gz
		${DRUPAL_SITE}statistics_filter-${MOD_PV}.tar.gz
		${DRUPAL_SITE}stock-${MOD_PV}.tar.gz
		${DRUPAL_SITE}subscriptions-${MOD_PV}.tar.g
		${DRUPAL_SITE}summary-${MOD_PV}.tar.gz
		${DRUPAL_SITE}survey-${MOD_PV}.tar.gz
		${DRUPAL_SITE}syndication-${MOD_PV}.tar.gz
		${DRUPAL_SITE}taxonomy_access-${MOD_PV}.tar.gz
		${DRUPAL_SITE}taxonomy_block-${MOD_PV}.tar.gz
		${DRUPAL_SITE}taxonomy_browser-${MOD_PV}.tar.gz
		${DRUPAL_SITE}taxonomy_dhtml-${MOD_PV}.tar.gz
		${DRUPAL_SITE}taxonomy_xml-${MOD_PV}.tar.gz
		${DRUPAL_SITE}taxonomy_menu-${MOD_PV}.tar.gz
		${DRUPAL_SITE}taxonomy_multi_edit-${MOD_PV}.tar.gz
		${DRUPAL_SITE}textile-${MOD_PV}.tar.gz
		${DRUPAL_SITE}theme_editor-${MOD_PV}.tar.gz
		${DRUPAL_SITE}tinymce-${MOD_PV}.tar.gz
		${DRUPAL_SITE}troll-${MOD_PV}.tar.gz
		${DRUPAL_SITE}urlfilter-${MOD_PV}.tar.gz
		${DRUPAL_SITE}variable-${MOD_PV}.tar.gz
		${DRUPAL_SITE}vimcolor-${MOD_PV}.tar.gz
		${DRUPAL_SITE}webform-${MOD_PV}.tar.gz
		${DRUPAL_SITE}webserver_auth-${MOD_PV}.tar.gz
		${DRUPAL_SITE}week-${MOD_PV}.tar.gz"

DRUPAL_CORRUPT="${DRUPAL_SITE}paypal_framework-${MOD_PV}.tar.gz
		${DRUPAL_SITE}daily-${MOD_PV}.tar.gz
		${DRUPAL_SITE}webform-${MOD_PV}.tar.gz"

#markssmarty can be chosen instead of smarty, not together.
#sxip is a way of single signon across sites.

DRUPAL_MODS_TODO="${DRUPAL_SITE}marksmarty-${MOD_PV}.tar.gz
		${DRUPAL_SITE}sixp-${MOD_PV}.tar.gz"

DRUPAL_THEMES="${DRUPAL_SITE}adc-${MOD_PV}.tar.gz
		${DRUPAL_SITE}blix-${MOD_PV}.tar.gz
		${DRUPAL_SITE}bluemarine-${MOD_PV}.tar.gz
		${DRUPAL_SITE}democratica-${MOD_PV}.tar.gz
		${DRUPAL_SITE}friendselectric-${MOD_PV}.tar.gz
		${DRUPAL_SITE}gespaa-${MOD_PV}.tar.gz
		${DRUPAL_SITE}goofy-${MOD_PV}.tar.gz
		${DRUPAL_SITE}greenmarinee-${MOD_PV}.tar.gz
		${DRUPAL_SITE}interlaced-${MOD_PV}.tar.gz
		${DRUPAL_SITE}leaf-${MOD_PV}.tar.gz
		${DRUPAL_SITE}lincolns_revenge-${MOD_PV}.tar.gz
		${DRUPAL_SITE}marvinclassic-${MOD_PV}.tar.gz
		${DRUPAL_SITE}rdc-${MOD_PV}.tar.gz
		${DRUPAL_SITE}slash-${MOD_PV}.tar.gz
		${DRUPAL_SITE}slurpee-${MOD_PV}.tar.gz
		${DRUPAL_SITE}spreadfirefox-${MOD_PV}.tar.gz
		${DRUPAL_SITE}sunflower-${MOD_PV}.tar.gz
		${DRUPAL_SITE}unconed-${MOD_PV}.tar.gz"

SRC_URI="http://drupal.org/files/projects/${P}.tar.gz
		!minimal? ( ${DRUPAL_SITE}phptemplate-${MOD_PV}.tar.gz
			${DRUPAL_MODS} 
			${DRUPAL_THEMES} )"

LICENSE="GPL-2"
KEYWORDS="~x86"

DEPEND="virtual/php"

src_unpack() {
	local themes mods
	cd ${WORKDIR}
	unpack ${P}.tar.gz 
	cd ${S}
	if ! use minimal; then
		einfo "installing modules, no minimal in USE."
		cd themes/engines
		unpack phptemplate-${MOD_PV}.tar.gz 
		cd ${S}/themes
		for themes in ${DRUPAL_THEMES}; do
			unpack ${themes/${DRUPAL_SITE}} 
		done
		cd ${S}/modules
		for mods in ${DRUPAL_MODS}; do 
			unpack ${mods/${DRUPAL_SITE}} 
		done
		ewarn "${DRUPAL_CORRUPT}"
		ewarn "are corrupted archives. If you need these," 
		ewarn "STOP EMERGING NOW!"
		sleep 5
	fi
	if ! use cleanup && ! use minimal; then
		einfo "${MOD_PV} modules get updated within the ${MOD_PV} timeframe"
		einfo "of Drupal."
		einfo "Because of this we cannot garanty ANY safety on these sources."
		einfo "Put 'cleanup' in USE and all modules will be deleted after a"
		einfo "successfull build, so you can reemerge them once in awhile ;)"
		sleep 5
	fi
}

src_compile() {
	echo "Nothing to compile."
}

src_install() {

	local docs="MAINTAINERS.txt LICENSE.txt INSTALL.txt CHANGELOG.txt"

	webapp_src_preinst

	# handle documentation files
	#
	# NOTE that doc files go into /usr/share/doc as normal; they do NOT
	# get installed per vhost!

	einfo "Installing docs"
	cd ${WORKDIR}/${P}
	dodoc ${docs}
	for doc in ${docs}; do
		rm -f ${doc}
	done

	einfo "Copying main files" 
	cp -R * ${D}${MY_HTDOCSDIR}

	# we install the .htaccess file to enable support for clean URLs
	cp .htaccess ${D}${MY_HTDOCSDIR}

	# create the files upload directory
	mkdir ${D}${MY_HTDOCSDIR}/files
	webapp_serverowned ${MY_HTDOCSDIR}/files

	# Identify any script files that need #! headers adding to run under
	# a CGI script (such as PHP/CGI)
	#
	# for drupal, we *assume* that all .php files need to have CGI/BIN
	# support added
	for x in `find . -name '*.php' -print ` ; do
		webapp_runbycgibin php ${MY_HTDOCSDIR}/$x
	done

	#All files must be owned by server
	for x in `find . -type f -print` ; do
		webapp_serverowned ${MY_HTDOCSDIR}/$x
	done

	webapp_configfile ${MY_HTDOCSDIR}/sites/default/settings.php
	webapp_postinst_txt en ${FILESDIR}/postinstall-en.txt
	webapp_src_install

	#modules get updated within PV of drupal, so I used USE to
	#cleanup.
	if use cleanup; then
		for to_delete in ${DRUPAL_MODS} ${DRUPAL_THEMES}; do
			rm ${DISTDIR}/${to_delete/${DRUPAL_SITE}}
		done
		einfo "Modules deleted from ${DISTFILES}."
	fi
}

